package code;

import java.util.Scanner;

public class Key_meituan1_day08 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n=sc.nextInt();
        for (int i=0;i<n;i++){
            String answer=sc.next();
            answer=GetAnswer(answer);
            System.out.println(answer);
        }

    }
    public static String GetAnswer(String str){
        char[] ch = str.toCharArray();
        int p=0;
        String answer="";
        for(int i=0;i<ch.length;i++){
            //如果为数字
            if(Character.isDigit(ch[i])){
                if(p==0){
                    p=Character.getNumericValue(ch[i]);
                }
                else{
                    p=10*p+Character.getNumericValue(ch[i]);
                }
            }
            else{
                answer=Offset(answer,p);
                p=0;
                if(ch[i]=='R'){
                   answer= new StringBuilder(answer).reverse().toString();
                }else {
                    answer=answer+ch[i];
                }
            }
        }
        return answer;
    }
    public static String Offset(String str,int p){
        if(str==null||str.isEmpty()){
            return str;
        }
        int len=str.length();
        p=p%len;
        if(p<0){
            p+=len;
        }
        return str.substring(p,len)+str.substring(0,p);
    }

}
